package com.sdk.es.sdk.entity.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

@AllArgsConstructor
@NoArgsConstructor
@Data
@Accessors(chain = true)
public class EsPageResult<T> {

    private Integer current;

    private Long pages;

    private Integer size;

    private Long total;

    private List<T> records;

    public static <T> EsPageResult<T> of(List<T> records, Long total) {
        EsPageResult<T> result = new EsPageResult<>();
        result.setRecords(records);
        result.setSize(records.size());
        result.setTotal(total);
        return result;
    }

    public static <T> EsPageResult<T> of(List<T> records, Long total, Integer pageSize, Integer pageNum, Long pages) {
        EsPageResult<T> result = new EsPageResult<>();
        result.setRecords(records);
        result.setTotal(total);
        result.setSize(pageSize);
        result.setCurrent(pageNum);
        result.setPages(pages);
        return result;
    }
}
